<template>
  <div>
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item><b>安全审计</b></el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxs" style="padding-top:10px;height: 45px; overflow: hidden;">
        <el-form :inline="true" :model="filters">
          <div>
            <el-form-item label="用户名">
              <el-input v-model="filters.userName"
                style="width: 150px;"></el-input>
            </el-form-item>
            <el-form-item label="访问时间">
              <el-date-picker
                value-format="yyyy-MM-dd"
                style="width: 150px;"
                v-model="filters.accessTime"
                />
            </el-form-item>
            <el-form-item label="IP地址">
              <el-input v-model="filters.remoteAddr"
                style="width: 200px;"></el-input>
            </el-form-item>
            <el-form-item label="请求页面">
              <el-input v-model="filters.referer" placeholder="关键字"></el-input>
            </el-form-item>
            <el-form-item label="请求接口">
              <el-input v-model="filters.requestUri" placeholder="关键字"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="getUpdatelogList" icon="el-icon-search">查询</el-button>
            </el-form-item>
            <el-form-item>
              <el-button icon="el-icon-download" type="success" style="float:right;margin-left:10px" @click="exportAll()">导出查询结果</el-button>
            </el-form-item>
          </div>
        </el-form>
    </section>
    <section class="wboxd" style="margin-top:10px">
      <!--列表-->
      <h1>安全审计</h1>
      <el-table :data="updateLogList" highlight-current-row v-loading="LogListLoading" style="width: 100%;" :height="tableHeight" border>
        <el-table-column type="index" label=" " width="50" fixed align="center" class-name="tableth">
        </el-table-column>
          <el-table-column label="用户名" prop="userName" width="150" show-overflow-tooltip />
          <el-table-column label="访问时间" prop="accessTime" width="200" show-overflow-tooltip />
          <el-table-column label="IP地址" prop="remoteAddr" width="150" show-overflow-tooltip />
          <el-table-column label="请求方式" prop="requestMethod" width="130" />
          <el-table-column label="响应状态码" prop="status" width="130" />
          <el-table-column label="响应体字节数" prop="bodyBytesSent" width="130" />
          <el-table-column label="客户端浏览器" prop="userAgent" width="200" show-overflow-tooltip />
          <el-table-column label="请求页面" prop="referer" width="200" show-overflow-tooltip />
          <el-table-column label="请求接口URI及参数" prop="requestUri" show-overflow-tooltip />
      </el-table>
      <div class="block">
        <el-pagination :total="logTotalNum" :current-page="logPageNum" :page-size="logPageSize" @current-change="loghandleCurrentChange" @size-change="loghandleSizeChange" :page-sizes="[10, 20, 30, 50]" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
      </div>
    </section>
  </div>
</template>

<script>
export default {
  data () {
    return {
      filters: {
        unitName: '',
        userName: '',
        accessTime: '',
        remoteAddr: '',
        referer: '',
        requestUri: ''
      },
      updateLogText: {},
      updateLogList: [],
      LogListLoading: false,
      logTotalNum: 0,
      logPageNum: 1,
      logPageSize: 20,
      tableHeight: 100
    }
  },
  methods: {
    exportAll () {
      var form = document.createElement('form')
      form.setAttribute('method', 'post')
      form.setAttribute('target', '_blank')
      var input = document.createElement('input')
      if (this.filters.userName) {
        input = document.createElement('input')
        input.setAttribute('type', 'hidden')
        input.setAttribute('name', 'userName')
        input.setAttribute('value', this.filters.userName)
        form.append(input)
      }
      if (this.filters.accessTime) {
        input = document.createElement('input')
        input.setAttribute('type', 'hidden')
        input.setAttribute('name', 'accessTime')
        input.setAttribute('value', this.filters.accessTime)
        form.append(input)
      }
      if (this.filters.remoteAddr) {
        input = document.createElement('input')
        input.setAttribute('type', 'hidden')
        input.setAttribute('name', 'remoteAddr')
        input.setAttribute('value', this.filters.remoteAddr)
        form.append(input)
      }
      if (this.filters.referer) {
        input = document.createElement('input')
        input.setAttribute('type', 'hidden')
        input.setAttribute('name', 'referer')
        input.setAttribute('value', this.filters.referer)
        form.append(input)
      }
      if (this.filters.requestUri) {
        input = document.createElement('input')
        input.setAttribute('type', 'hidden')
        input.setAttribute('name', 'requestUri')
        input.setAttribute('value', this.filters.requestUri)
        form.append(input)
      }
      form.setAttribute('action', this.$http.defaults.baseURL + 'audit/download')
      document.body.appendChild(form)
      form.submit()
      form.remove()
      // let para = {}
      // para = {
      //   userName: this.filters.userName,
      //   accessTime: this.filters.accessTime,
      //   remoteAddr: this.filters.,
      //   referer: this.filters.,
      //   requestUri: this.filters.
      // }
      // this.$http
      //   .post('/audit/download', para)
      //   .then((response) => {
      //     if (response.data.isSuccess === true) {
      //       window.location.href = response.data
      //     } else {
      //       console.log('导出查询结果失败:' + response.data.Msg)
      //       this.$message({
      //         message: '导出查询结果失败:' + response.data.Msg,
      //         type: 'error'
      //       })
      //     }
      //   })
      //   .catch((error) => {
      //     this.$message({
      //       message: '网络获取失败:' + error,
      //       type: 'error'
      //     })
      //   })
    },
    loghandleSizeChange (val) {
      this.changeLogSizeFlag = true
      this.logPageNum = 1
      this.logPageSize = val
      this.getUpdatelogList()
    },
    loghandleCurrentChange (val) {
      if (this.changeLogSizeFlag === false) {
        this.logPageNum = val
        this.getUpdatelogList()
      }
    },
    getUpdatelogList () {
      this.LogListLoading = true
      let para = {}
      para = {
        pageNum: this.logPageNum,
        pageSize: this.logPageSize,
        userName: this.filters.userName,
        accessTime: this.filters.accessTime,
        remoteAddr: this.filters.remoteAddr,
        referer: this.filters.referer,
        requestUri: this.filters.requestUri
      }
      this.$http
        .post('/audit/queryByPage', para)
        .then((response) => {
          // if (response.data.isSuccess === true) {
          this.updateLogList = response.data.list
          this.logTotalNum = response.data.total
          this.LogListLoading = false
          this.changeLogSizeFlag = false
          // } else {
          //   console.log('查询失败:' + response.data.Msg)
          //   this.$message({
          //     message: '查询失败:' + response.data.Msg,
          //     type: 'error'
          //   })
          // }
        })
        .catch((error) => {
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - 295
      })
    }
  },
  mounted () {
    this.getUpdatelogList()
    this.tableresize(this)
    let _this = this
    window.onresize = function windowResize () {
      // 通过捕获系统的onresize事件触发我们需要执行的事件
      _this.tableresize(_this)
    }
  }
}
</script>
<style>
.selectioncontent{
  border-bottom:1px solid #333;
  padding:5px !important;
}
  .pointtab .el-badge__content.is-fixed{
    right: -5px;
    top:18px;
  }
  .pointtab{
    padding-right:22px;
  }
  .pointRadio .el-badge__content.is-fixed{
    right: -5px;
    top:6px;
  }
  .pointRadio .el-radio-button__inner{
    height:40px;
    padding-left:15px;
    padding-right:42px;
  }
#recruitlist .el-table--border td, .el-table--border th, .el-table__body-wrapper .el-table--border.is-scrolling-left~.el-table__fixed{
  border-bottom:1px solid #95B8E7;
}
#recruitlist .el-table td, #recruitlist .el-table th.is-leaf{
  border-right:1px solid #95B8E7;
}
  .wboxd .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    text-align: center;
    border-right: #95B8E7 solid 1px;
    border-bottom: #95B8E7 solid 1px;
    min-height: 30px;
    line-height:30px;
  }
  .wboxd .el-table td{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体',
  }
  .tableth{
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    height:33px;
  }
  #recruitlist .wboxs{
    height:45px;
    padding-top:10px;
  }
  #recruitlist .el-table__row{
    height: 50px;
  }
  #recruitlist #legent{
    float:right;
    margin-right: 20px;
  }
  #recruitlist #legent div{
    float:left;
    line-height: 42px;
    font-size:var(--size12);
  }
  #recruitlist #legent i{
    width: 30px;
    height: 30px;
    background-position: center center;
    background-repeat: no-repeat;
    float: left;
    display: block;
    margin:5px 0px 0 3px;
  }
  #recruitlist #selectionindexlist .cell i.custom{
    width: 30px;
    height: 30px;
    background-position: center center;
    background-repeat: no-repeat;
    float: left;
    display: block;
    margin:0 auto;
  }
  #recruitlist #selectionindexlist .cell button i{
    width: var(--size14);
    height: var(--size14);
  }
  #recruitlist .icon_c_0{
    background-image: url(../assets/icon_selection_index0.png)
  }
  #recruitlist .icon_c_1{
    background-image: url(../assets/icon_selection_index2.gif)
  }
  #recruitlist .icon_c_2{
    background-image: url(../assets/icon_selection_index1.png)
  }
  #recruitlist .icon_c_-1{
    background-image: url(../assets/icon_selection_index-1.png)
  }
  #recruitlist .icon_c_3{
    background-image: url(../assets/icon_selection_index3.png)
  }
  #recruitlist .icon_c_3a{
    background-image: url(../assets/icon_selection_index4t.png)
  }
  #recruitlist .icon_c_3b{
    background-image: url(../assets/icon_selection_index3b.png)
  }
  #recruitlist .icon_c_4{
    background-image: url(../assets/icon_selection_index4t.png)
  }
  #recruitlist .icon_c_5{
    background-image: url(../assets/icon_selection_index4r.png)
  }
  #recruitlist .icon_gd_0{
    background-image: url(../assets/icon_selection_gd0.png)
  }
  #recruitlist .icon_gd_1{
    background-image: url(../assets/icon_selection_gd1.gif)
  }
  #recruitlist .icon_gd_2{
    background-image: url(../assets/icon_selection_gd2.png)
  }
  #recruitlist .icon_gd_4{
    background-image: url(../assets/icon_selection_gd4.png)
  }
  #recruitlist .el-step__title.is-finish {
    color: #409EFF;
  }
  #recruitlist .el-step__title {
    font-size:12px;
    line-height: 22px;
    padding-left: 8px;
  }
  #recruitlist .el-steps{
    margin:10px 0;
  }
  .el-tooltip__popper.is-dark{
    font-size:var(--size18) !important;
  }
  .el-tabs--card>.el-tabs__header {
    border-bottom: 1px solid #9CA3B3;
  }
  .el-tabs--card>.el-tabs__header .el-tabs__nav {
    border: 1px solid #9CA3B3;
    border-bottom: 0;
  }
  .el-tabs--card>.el-tabs__header .el-tabs__item {
    border-left: 1px solid #9CA3B3;
    /* background-color: #F0F0F0; */
  }
  .el-tabs__item.is-active {
    color: #0000FF !important;
    font-weight: bolder !important;
    /* background-color: #fff !important; */
    /* border-bottom: 2px solid #9CA3B3 !important; */
  }
</style>
<style scoped>
  .el-tooltip__popper{
    font-size:var(--size) !important;
  }
  h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  .wboxs{
    padding:5px 15px;
    width: calc(100% - 30px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
  .wboxd{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
</style>
